﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BKH.BLL
{
    public struct Chit
    {
        static Chit()
        {
            
        }
    }
    class ChiTietLichTrucBUO:IBUO<tbl_ChiTietLichTruc>
    {
        HospitalDBDataContext context = new HospitalDBDataContext();
        public bool Insert(tbl_ChiTietLichTruc obj)
        {
            try
            {

                context.tbl_ChiTietLichTrucs.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {
                
                return false;
            }
        }

        public bool Delete(int id)
        {

            try
            {
                tbl_ChiTietLichTruc item = context.tbl_ChiTietLichTrucs.Where(n => n.ChiTietLichID == id).ToList<tbl_ChiTietLichTruc>().FirstOrDefault();
                context.tbl_ChiTietLichTrucs.DeleteOnSubmit(item);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool Delete(tbl_ChiTietLichTruc obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_ChiTietLichTruc> GetAll()
        {
            throw new NotImplementedException();
        }

        public tbl_ChiTietLichTruc GetSingle(int id)
        {
            throw new NotImplementedException();
        }

        public bool Update(int id, tbl_ChiTietLichTruc obj)
        {
            throw new NotImplementedException();
        }
        public void GetLichTruc(int idLichTruc)
        {
            var t =context.tbl_ChiTietLichTrucs.Join(context.tbl_LichTrucs, c => c.LichTrucID, d => d.LichTrucID,
                  (c, d) => new
                  {
                      ChitietLichID = c.ChiTietLichID,
                      NhanVienID = c.NhanVienID,
                      CaTruc = c.CaTrucID,
                      LichTrucID = d.LichTrucID,

                  }
                  ).Where(k => k.LichTrucID == idLichTruc).Join(context.tbl_NhanViens, c => c.NhanVienID, d => d.NhanVienID, (c, d) => new
                  {
                      SoSoNV = d.NhanVienID,
                      HoTen = d.FirstName + " " + d.LastName,
                      Adress = d.Address,
                      Tel = d.Tel,
                      CaTruc = c.CaTruc,
                      ViTriID = d.Position



                  }).Join(context.tbl_Positions, c => c.ViTriID, d => d.PositionId, (c, d) => new
                  {
                      SoSoNV = c.SoSoNV,
                      HoTen = c.HoTen,
                      Adress = c.Adress,
                      Tel = c.Tel,
                      CaTruc = c.CaTruc,
                      ViTri = d.PositionName

                  });
          
        }
    }
}
